package com.chenwy.example;

import org.jetbrains.annotations.NotNull;

import java.util.*;

class Student implements Comparable<Student>,Comparator<Student>{
    final String name;
    final int score;

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, score);
    }

    @Override
    public int compare(Student o1, Student o2) {
        int n  = Integer.compare(o1.score ,o2.score);
        return n != 0 ? n : o1.name.compareTo(o2.name);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Student) {
            Student o = (Student) obj;
            return Objects.equals(this.name, o.name) && this.score == o.score;
        }
        return false;
    }

    @Override
    public int compareTo(@NotNull Student o) {
        int n  = Integer.compare(this.score ,o.score);
        return n != 0 ? n : this.name.compareTo(o.name);
    }
}
public class DoubleEqualTest {

    public static void main(String[] args) {
        //
        Long time = 1571380471576L;
        Date date = new Date();
        date.setTime(time);
//        System.out.println(time.equals(date));
        date = null ;
        System.out.println(date instanceof  Date);
        Map<Student, Integer> map = new TreeMap<>();
        map.put(new Student("Michael", 99), 99);
        map.put(new Student("Bob", 88), 88);
        map.put(new Student("Alice", 77), 77);
        System.out.println(map.get(new Student("Michael", 99)));
        System.out.println(map.get(new Student("Bob", 88)));
        System.out.println(map.get(new Student("Alice", 77)));
    }
}
